package tothreedesignmodel.iterator;

import lombok.Data;

import java.util.List;

/**
 * @author lzhphantom
 * @description
 * @date 创建于 23:33 2020/8/1
 * @modified
 */
@Data
public class ConcreteIterator<T> implements Iterator<T> {
    private List<T> list = null;
    private int index = -1;

    public ConcreteIterator(List<T> list) {
        this.list = list;
    }

    @Override
    public T first() {
        index = 0;
        return list.get(index);
    }

    @Override
    public T next() {
        return hasNext() ? list.get(++index) : null;
    }

    @Override
    public boolean hasNext() {
        return index < list.size() - 1;
    }
}
